<script type="text/javascript">
function cariAbhp(){
	var id_ppk=$('#nama_ppk').val();
	popupCari('module/mod_klaim/js/popup_abhp.php?id_ppk='+id_ppk);
}

function hapusAbhp(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
		kalkulasi_abhp();
	}
}

function kalkulasi_abhp(){
	//alert('coba');
	var jumlah_invoice=0;
	jumlah_invoice=hitung_total_invoice_abhp();
	//alert('jumlah invoice '+jumlah_invoice);
	$('#total_abhp').val(jumlah_invoice);
	$('#target_total_abhp').html(number_format(jumlah_invoice, 0, ',','.'));
	hitung_semua_klaim();
}
function hitung_total_invoice_abhp(){
	//alert('kocor');
		var frm=document.forms['form_klaim'];
		var harga_brg=frm.elements['harga_abhp[]'];
		var jml_pesanan=frm.elements['jumlah_abhp[]'];
		//alert(harga_brg+' dan '+jml_pesanan);
		if(harga_brg==undefined){
			return 0;
		}
		n=jml_pesanan.length;
		var total=0;
		var sub_total=0
		if(n>1){
			for(var i=0;i<n;i++){
				sub_total=parseFloat(jml_pesanan[i].value)*parseFloat(harga_brg[i].value);
				total+=sub_total;
			}
		}else{
			sub_total=parseFloat(jml_pesanan.value)*parseFloat(harga_brg.value);
			total+=sub_total;
		}
		//alert(total);
		return total;
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><table class="tabel" width="90%">
           <tr>
             <th scope="col">Nama ABHP </th>
             <th scope="col">Jumlah</th>
             <th scope="col">Harga Ditanggung </th>
             <th scope="col">Harga Diminta </th>
             <th scope="col">&nbsp;</th>
           </tr>
			<tbody id="tbody_list_abhp">
			<?php
			$sql_obat="select a.id_abhp, b.nama,a.jumlah,c.tarif,a.tarif_ditanggung 
						from klaim_abhp a inner join master_abhp b on a.id_abhp=b.id_abhp 
						inner JOIN tarif_abhp c ON b.id_abhp=c.id_abhp
					 where a.id_klaim='".$id_klaim."'";
				//echo $sql_obat;
			$qry_obat=mysql_query($sql_obat);
			$num_obat=mysql_num_rows($qry_obat);
			//echo 'num hasil '.$num_obat;
			$no=1;
			if(!empty($id_klaim)&& $num_obat>0){
				while($hasil_abhp=mysql_fetch_array($qry_obat)){
			?>
			<tr>
			<td><?php echo $hasil_abhp['nama']; ?><input type="hidden" name="id_abhp[]"  value="<?php echo $hasil_abhp['id_abhp']; ?>"></td>
			<td><input type="text" size="5" id="jumlah_abhp_<?php echo $no;?>" name="jumlah_abhp[]" value="<?php echo $hasil_abhp['jumlah']; ?>"></td>
			<td><?php echo $hasil_abhp['tarif']; ?></td>
			<td><input type="text" size="5" id="harga_abhp_<?php echo $no;?>" name="harga_abhp[]" value="<?php echo $hasil_abhp['tarif_ditanggung']; ?>"></td>
			<td><a href="javascript:void(null)" title="Hapus" onclick="hapusAbhp(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a></td>
			</tr>
			<?php 
			}
				$count_abhp=$num_abhp+1;
			}else{
				$count_abhp=1;
			}
			?>
		   </tbody>
</table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
       <td><a href="javascript:void(0)" title="Tambah" onclick="cariAbhp()"><img src="asset/images/button-add.gif" alt="Tambah" border=0 /></a></td>
       <td><input type="hidden" id="count_abhp" value="<?php echo $count_abhp;?>" /></td>
  </tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Sub Total </td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_total_abhp" style="font-weight:bold;"></div><input type="hidden" id="total_abhp" value="0" /></td>
  </tr>
</table>


